import axios from "axios";
import { getToken } from "./auth";
import { Message } from "element-ui";

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'

const service = axios.create({
    baseURL: process.env.VUE_APP_BASE_API,
    timeout: 30000,
    headers: {
		'Cache-Control': 'no-cache',
	},
})

service.interceptors.request.use(config => {
    const isToken = (config.headers || {}).isToken === false;
    if(!isToken) {
        const token = getToken();
        if(token) {
            config.headers['Authorization'] = token;
        }
    }
    return config;
}, error => {
    console.log(error)
    Promise.reject(error)
})
service.interceptors.response.use(res => {
    return res;
})

export default service;